<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title>收货地址 {$site_name}</title>
	<meta name="keywords" content="{$site_seo_keywords}" />
	<meta name="description" content="{$site_seo_description}">
	<tc_include file="Public:head" />	
</head>
<body>
<style type="text/css">
	body{
		min-width:100%;
		width:100%;
	}
	label.error{
		display:block;
	}
	.city-box label{
		left:137px;
	}
	.district-box label{
		left:273px;
	}
</style>
<script type="text/javascript">
	jQuery.validator.addMethod("mobile", function(value, element) {   
		var mobile = /(^(13\d|15[^4\D]|17[13678]|18\d)\d{8}|170[^346\D]\d{7})$/;
		return this.optional(element) || (mobile.test(value));
	}, "请正确填写手机号码");
</script>

<div class="adderss-box">    
        <div class="box-bd">
            <div class="box-header">                
                <span class="box-title">收货信息</span>
            </div>
            <form action="" method="post" id="val-form" class="">
				<input type="hidden" name="address_id" value="{$address.address_id}" />
                <table width="90%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td align="right"><span class="bd-title">收货人：&nbsp;</span></td>
                        <td><input class="k-input" name="consignee" type="text" value="{$address.consignee}" maxlength="12" /></td>
                    </tr>
                    <tr>
                        <td align="right"><span class="bd-title">收货地址：&nbsp;</span></td>
                        <td>
							<div class="province-box select-box">
								<select class="k-select fl" name="province" id="province" onChange="get_city(this)">
									<option value="">请选择</option>
									<volist name="province" id="p">
										<option <if condition="$address['province'] eq $p['id']">selected</if>  value="{$p.id}">{$p.name}</option>
									</volist>
								</select>
							</div>
                            <div class="city-box select-box">
								<select class="k-select fl" name="city" id="city" onChange="get_area(this)">
									<option  value="">请选择</option>
									<volist name="city" id="p">
										<option <if condition="$address['city'] eq $p['id']">selected</if>  value="{$p.id}">{$p.name}</option>
									</volist>
								</select>
							</div>
							<div class="district-box select-box">
								<select class="k-select fl" name="district" id="district" onChange="get_twon(this)">
									<option  value="">请选择</option>
									<volist name="district" id="p">
										<option <if condition="$address['district'] eq $p['id']">selected</if>  value="{$p.id}">{$p.name}</option>
									</volist>
								</select>
							</div>                                                        
                            <select class="k-select fl" name="twon" id="twon" <if condition="$address['twon'] gt 0 ">style="display:block;"<else/>style="display:none;"</if>>
                            	<volist name="twon" id="p">
                                    <option <if condition="$address['twon'] eq $p['id']">selected</if>  value="{$p.id}">{$p.name}</option>
                                </volist>
                            </select>
                            <br>
                        </td>
                    </tr>
                    <tr>
                    	<td align="right" valign="top"><span class="bd-title">详细地址：&nbsp;</span></td>
                    	<td><textarea class="k-textarea" name="address" id="address" placeholder="详细地址" maxlength="100">{$address.address}</textarea></td>
                    </tr>                    
                    <tr>
                        <td align="right"><span class="bd-title">手机：&nbsp;</span></td>
                        <td><input class="k-input" type="text" name="mobile" value="{$address.mobile}" onpaste="this.value=this.value.replace(/[^\d-]/g,'')" onKeyUp="this.value=this.value.replace(/[^\d-]/g,'')" maxlength="15"/></td>
                    </tr>
                    <tr>
                        <td class="">&nbsp;</td>
                        <td align="left">
                            <button type="submit" class="btn btn-on btn-ajax-submit">保存收货信息</button>
                        </td>    
                    </tr>
                </table>

            </form>
        </div>   
</div>
<tc_include file="Public:scripts" />	
<script>
$.validator.setDefaults({
    submitHandler: function() {
	  var _id = $("input[name='address_id']").val();
	  if(!_id){
		var _url = "{:U('user/address/addAddress')}";
	  }else{
		var _url = "{:U('user/address/editAddress')}";
	  }
	
      $.ajax({
			type: "POST",
			url: _url,	
			data: $('#val-form').serialize(),
			dataType: "json",
			success: function(data){
			if(data.status > 0){
				window.parent.default_address();  //执行获取地址函数
				var index = parent.layer.getFrameIndex(window.name);				
				parent.layer.close(index);
			}else{
				layer.msg(data.msg);
			}						
			}
		});
    }
});
$().ready(function() {
  $("#val-form").validate({
	    rules: {	     	      
	      consignee: {
	        required: true,
	      },
		  province: {
	        required: true,
	      },
		  city: {
	        required: true,
	      },
		  district: {
	        required: true,
	      },
	      address: {
	        required: true,
	      },
		  mobile: {
	        required: true,
			mobile:true
	      },		  
	    },
	    messages: {	     
	      consignee: {
	        required: "收货人姓名不能为空",	       
	      },
		  province: {
	        required: "省不能为空",	       
	      },
		  city: {
	        required: "市不能为空",	       
	      },
		  district: {
	        required: "区不能为空",	       
	      },
	      address: {
	        required: "详细地址不能为空",
	      },
	      mobile: {
	        required: "手机地址不能为空",
			mobile: "请正确填写手机号码"
	      },
	    }
		
	});
});
</script>

</body>
</html>